<?php
namespace app\mall\logic;

use think\facade\Db;

class walletLogic{

    /**
     * 资产明细记录添加
     * @param int $uid 用户id
     * @param float $money 变动金额
     * @param int $type 1:支付宝充值  2:微信充值  3:后台充值  4:购买 5:提现  6:兑换 7:分佣 8:积分返还
     * @param int $genre 1:余额   2:积分
     * @param int $source_id 来源id
     * @param string $symbol 类型 增加 add 减少 reduce
     * @param string $memo 备注
     */
    public static function wallet_detailed_add(int $uid ,float $money ,int $type ,int $genre ,int $source_id = 0 ,string $symbol = 'add',string $memo=''){
        switch ($genre){
            case 1:
                $money_before = Db::table('one_user_wallet')->where('u_id','=',$uid)->value('money');
                break;
            case 2:
                $money_before = Db::table('one_user_wallet')->where('u_id','=',$uid)->value('integral');
                break;
            default:
                return false;
        }
        $money_after = $symbol == 'add' ? $money_before+$money : $money_before-$money;
        $data = array(
            'u_id' => $uid,
            'money' => $money,
            'type' => $type,
            'genre' => $genre,
            'source_id' => $source_id,
            'symbol' => $symbol,
            'money_before' => $money_before,
            'money_after' => $money_after,
            'memo' => $memo,
            'create_time'=>date('Y-m-d H:i:s')
        );
        return Db::table('one_user_wallet_detailed')->insertGetId($data);
    }

}